import DataSet, { DataSetProps } from 'choerodon-ui/pro/lib/data-set/DataSet';
import { FieldType } from 'choerodon-ui/pro/lib/data-set/enum';
import request from 'utils/request';
import { API_HOST } from 'utils/config';
// import { getUrlParamHref, getLovDefineAxiosConfig, getLovQueryAxiosConfig } from './utils';

export const TableListDataSetConfig = (lineBoCode): DataSetProps => {
  return {
    autoQuery: true,
    autoCreate: false,
    // selection: false,
    pageSize: 10,
    paging: true,
    transport: {
      submit: ({ data }) => {
        return {
          url: `/hmde/v1/executor/${lineBoCode}/batch-update`,
          method: 'POST',
          data,
        };
      },
      read: ({ params }) => {
        return {
          url: `/hmde/v1/executor/${lineBoCode}/page`,
          method: 'GET',
          params: {
            ...params,
            sort: 'creationDate,DESC',
          },
        };
      },
      destroy: ({ data }) => {
        return {
          url: `/hmde/v1/executor/${lineBoCode}/batch-delete`,
          method: 'DELETE',
          data,
        };
      },
    },
    fields: [
      {
        name: 'documentNum',
        type: FieldType.string,
        label: '请求单编号',
      },

      {
        name: 'purposeCode',
        type: FieldType.string,
        label: '单证用途',
        options: new DataSet({
          data: [
            { value: '1', meaning: '委派服务' },
            { value: '2', meaning: '客户请求' },
          ]
        })
      },
      {
        name: 'acceptTypeCode',
        type: FieldType.string,
        label: '受理类型',
        options: new DataSet({
          data: [
            { value: '1', meaning: '整机受理' },
            { value: '2', meaning: '配件受理' },
            { value: '3', meaning: '其他受理' },
          ]
        })
      },
      {
        name: 'levelCode',
        type: FieldType.string,
        label: '紧急性',
        options: new DataSet({
          data: [
            { value: '1', meaning: '紧急' },
            { value: '2', meaning: '高' },
            { value: '3', meaning: '中' },
            { value: '4', meaning: '低' },
          ]
        })
      },
      {
        name: 'customerEmail',
        type: FieldType.email,
        label: '客户邮箱',
      },
      {
        name: 'customerMobile',
        type: FieldType.string,
        label: '客户手机',
      },
      {
        name: 'docTypeCode',
        type: FieldType.string,
        label: '单据类型',
      },
      {
        name: 'companyName',
        type: FieldType.string,
        label: '产品公司',
      },
      {
        name: 'customerFeedback',
        type: FieldType.string,
        label: '客户反馈内容',
      },
      {
        name: 'customerName',
        type: FieldType.string,
        label: '客户姓名',
      },
      {
        name: 'engineNumber',
        type: FieldType.string,
        label: '发动机编号',
      },
      {
        name: 'sourceTypeCode',
        type: FieldType.string,
        label: '来源类型',
        multiple: true,
        options: new DataSet({
          data: [
            { value: '1', meaning: '热线电话' },
            { value: '2', meaning: '微信服务请求' },
            { value: '3', meaning: '电商服务请求' },
            { value: '4', meaning: '主动服务平台请求' },
            { value: '5', meaning: '其他' },
          ]
        })
      },
      {
        name: 'requestTypeCode',
        type: FieldType.string,
        label: '请求类型',
        options: new DataSet({
          data: [
            { value: '1', meaning: '即时报修' },
            { value: '2', meaning: '服务预约' },
          ]
        })
      },
      {
        name: 'serviceTypeCode',
        type: FieldType.string,
        label: '服务类型',
        options: new DataSet({
          data: [
            { value: '1', meaning: '维修' },
            { value: '2', meaning: '保养' },
          ]
        })
      },
      {
        name: 'requestStartDate',
        type: FieldType.dateTime,
        label: '请求开始时间',
      },
      {
        name: 'responseEndDate',
        type: FieldType.dateTime,
        label: '响应截止时间',
      },
      {
        name: 'serviceStationRefuseDate',
        type: FieldType.dateTime,
        label: '服务站拒绝时间',
      },
      {
        name: 'serviceCompleteDate',
        type: FieldType.dateTime,
        label: '服务请求完成时间',
      },
      {
        name: 'purchaseDate',
        type: FieldType.date,
        label: '购车日期',
      },
      {
        name: 'carTypeCode',
        type: FieldType.string,
        label: '汽车类型（客户提供）',
        options: new DataSet({
          data: [
            { value: '1', meaning: '载货车' },
            { value: '2', meaning: '牵引汽车' },
            { value: '3', meaning: '自卸汽车' },
            { value: '4', meaning: '客车' },
            { value: '5', meaning: '公交车' },
            { value: '6', meaning: '收割机' },
            { value: '7', meaning: '拖拉机' },
            { value: '8', meaning: '发电机组' },
            { value: '9', meaning: '船机' },
            { value: '10', meaning: '空压机组' },
            { value: '11', meaning: '校车' },
            { value: '12', meaning: '钻机' },
            { value: '13', meaning: '搅拌车' },
            { value: '14', meaning: '挖掘机' },
            { value: '15', meaning: '装载机' },
            { value: '16', meaning: '叉车' },
            { value: '17', meaning: '环卫车' },
            { value: '18', meaning: '乘用车' },
            { value: '19', meaning: '汽车吊' },
            { value: '20', meaning: '随车吊' },
            { value: '21', meaning: '专用车' },
            { value: '22', meaning: '拖泵' },
            { value: '23', meaning: '消防车' },
            { value: '24', meaning: '压路机' },
            { value: '25', meaning: '邮政车' },
            { value: '26', meaning: '渣土车' },
            { value: '27', meaning: '皮卡' },
            { value: '28', meaning: '推土机' },
            { value: '29', meaning: '军用车' },
            { value: '30', meaning: '新能源车' },
            { value: '31', meaning: '其他' },
            { value: '32', meaning: '油罐车' },
            { value: '33', meaning: '混凝土泵车' },
          ]
        })
      },
      {
        name: 'sourceDocTypeCode',
        type: FieldType.string,
        label: '来源单据类型',
      },
      {
        name: 'acceptOpinions',
        type: FieldType.string,
        label: '受理意见',
      },
      {
        name: 'sourceDocNum',
        type: FieldType.string,
        label: '来源单号',
      },
      {
        name: 'requestEndDate',
        type: FieldType.dateTime,
        label: '请求结束时间',
      },
      {
        name: 'serviceAssignDate',
        type: FieldType.dateTime,
        label: '服务分派时间',
      },
      {
        name: 'serviceStationReceiveDate',
        type: FieldType.dateTime,
        label: '服务站接单时间',
      },
      {
        name: 'status',
        type: FieldType.string,
        label: '当前环节',
        options: new DataSet({
          data: [
            { value: 'NEW', meaning: '新建' },
            { value: 'PENDING1', meaning: '待办事处响应' },
            { value: 'PENDING2', meaning: '待服务站响应' },
            { value: 'EXECUTE', meaning: '服务站执行' },
            { value: 'COMPLETE', meaning: '服务已完成' },
            { value: 'RECEIVE', meaning: '呼叫中心接收' },
            { value: 'CANCEL', meaning: '作废' },
            { value: 'CANCEL0', meaning: '申请作废' },
            { value: 'CANCEL1', meaning: '作废处理中' },
            { value: 'CANCEL2', meaning: '拒绝作废' },
            { value: 'CHECK', meaning: '检查' },
          ]
        })
      },

      {
        name: 'creationDate',
        type: FieldType.dateTime,
        label: '创建时间',
      },
      {
        name: 'realName',
        type: FieldType.string,
        label: '创建人',
      },
      {
        name: 'productModel',
        type: FieldType.string,
        label: '产品型号',
      },
      {
        name: 'amount',
        type: FieldType.currency,
        label: '预估金额',
      },

      {
        name: 'serviceStationId',
        type: FieldType.string,
        label: '服务站',
      },
      {
        name: 'serviceStationName',
        type: FieldType.string,
        label: '服务站',
      },

      {
        name: 'officeId',
        type: FieldType.string,
        label: '办事处',
      },
      {
        name: 'officeName',
        type: FieldType.string,
        label: '办事处',
      },

      {
        name: 'subCompanyId',
        type: FieldType.string,
        label: '子公司',
      },
      {
        name: 'subCompanyName',
        type: FieldType.string,
        label: '子公司',
      },

      {
        name: 'businessSectorName',
        type: FieldType.string,
        label: '业务板块',
      },

    ],
    queryFields: [
      {
        name: 'documentNum',
        type: FieldType.string,
        label: '请求单编号',
      },
      {
        name: 'status',
        type: FieldType.string,
        label: '当前环节',
        options: new DataSet({
          data: [
            { value: 'NEW', meaning: '新建' },
            { value: 'PENDING1', meaning: '待办事处响应' },
            { value: 'PENDING2', meaning: '待服务站响应' },
            { value: 'EXECUTE', meaning: '服务站执行' },
            { value: 'COMPLETE', meaning: '服务已完成' },
            { value: 'RECEIVE', meaning: '呼叫中心接收' },
            { value: 'CANCEL', meaning: '作废' },
            { value: 'CANCEL0', meaning: '申请作废' },
            { value: 'CANCEL1', meaning: '作废处理中' },
            { value: 'CANCEL2', meaning: '拒绝作废' },
            { value: 'CHECK', meaning: '检查' },
          ]
        })
      },
      {
        name: 'engineNumber',
        type: FieldType.string,
        label: '发动机编号',
      },
      {
        name: 'requestTypeCode',
        type: FieldType.string,
        label: '请求类型',
        options: new DataSet({
          data: [
            { value: '1', meaning: '即时报修' },
            { value: '2', meaning: '服务预约' },
          ]
        })
      },
    ],
    events: {
      // update: ({ name, record }) => {
      //   if (['lineQuantity', 'unitPrice'].includes(name)) {
      //     const lineQuantity = record.get('lineQuantity');
      //     const unitPrice = record.get('unitPrice');
      //     if (typeof lineQuantity === 'number' && typeof unitPrice === 'number')
      //       record.set('lineAmount', lineQuantity * unitPrice);
      //   }
      // },
      // indexChange: ({ dataSet, record, previous }) => {
      // }
    }
  };
};

export const saveAll = ({ header, body, headerBoCode }) => {
  return request(
    `${API_HOST}/hmde/v1/executor/${headerBoCode}/batch-update`,
    {
      method: 'POST',
      data: body,
      headers: {
        ...header,
      },
    },
  );
};
